<%-- 
    Document   : inc_secretary_form
    Created on : Jan 12, 2013, 12:26:53 AM
    Author     : matt
--%>

<%@page import="com.gestionabsences.form.FormSecretary"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<table class="tab_form">
    <tr>
	<th><label for="<% out.print(FormSecretary.CHAMP_RANGE_QUERY);%>">Portée de la requête</label></th>
	<th class="operateur"><label for="<% out.print(FormSecretary.CHAMP_OPERATOR);%>">Opérateur</label></th>
	<th class="nbrAbsences"><label for="<% out.print(FormSecretary.CHAMP_NBRE_ABSENCES);%>">Nombre d'absences</label></th>
	<th class="listeEtudiants"><label for="<% out.print(FormSecretary.CHAMP_ETUDIANT);%>">Étudiant</label></th>
    </tr>
    <tr>
	<td>
	    <select class="typeRequete" name="<% out.print(FormSecretary.CHAMP_RANGE_QUERY);%>" id="<% out.print(FormSecretary.CHAMP_RANGE_QUERY);%>">
		<option value="SOME">Dans des cours</option>
		<option value="IN_ONE">Dans un des cours</option>
		<option value="ALL">Pour toutes les matières</option>
		<option value="PARTICULAR_STUDENT">Pour un étudiant</option>
	    </select>
	</td>
	<td class="operateur">
	    <select class="operator" name="<% out.print(FormSecretary.CHAMP_OPERATOR);%>" id="<% out.print(FormSecretary.CHAMP_OPERATOR);%>">
		<option class="SOMEselected" value=">">></option>
		<option class="IN_ONEselected" value=">=">>=</option>
		<option class="ALLselected"value="NEVER">Jamais absent</option>
		<option class="ALLselected" value="ALWAYS">Toujours absent</option>
	    </select>
	</td>
	<td class="nbrAbsences">
	    <input type="number" name="<% out.print(FormSecretary.CHAMP_NBRE_ABSENCES);%>" id="<% out.print(FormSecretary.CHAMP_NBRE_ABSENCES);%>" min="0" step="1" style="text-align:center;" />
	</td>
	<td class="listeEtudiants">
	    <select class="listeEtudiants" name="<% out.print(FormSecretary.CHAMP_ETUDIANT);%>" id="<% out.print(FormSecretary.CHAMP_ETUDIANT);%>">
		<c:forEach items="${ sessionScope.listeEtudiants }" var="mapEtudiants" varStatus="boucle">
		    <option value="${ mapEtudiants.key }">${ mapEtudiants.value }</option>
		</c:forEach>
	    </select>
	</td>
    </tr>
</table>
		
<c:if test="${ !empty form.erreurs['erreur'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>

<c:if test="${ !empty form.erreurs['range'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>

<c:if test="${ !empty form.erreurs['operateur'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>

<c:if test="${ !empty form.erreurs['nbrAbsences'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>
    
<c:if test="${ !empty form.erreurs['listeEtudiants'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
    $('.typeRequete').change(function () {
	//var str = "";
	
	var selectedOption = $('.typeRequete option:selected').val();
	if(selectedOption == "PARTICULAR_STUDENT") {
	    $('.nbrAbsences').css('display', 'none');
	    $('.operateur').css('display', 'none');
	    $('.listeEtudiants').css('display', 'block');
	} else {
	    $('.operateur').css('display', 'block');
	    
	    if( selectedOption == "ALL" ) {
		$('.nbrAbsences').css('display', 'none');
		
		$('.ALLselected').css('display', 'block');
		$('.SOMEselected').css('display', 'none');
		$('.IN_ONEselected').css('display', 'none');
		
	    } else if( selectedOption == "IN_ONE" ) {
		$('.nbrAbsences').css('display', 'block');
		
		$('.ALLselected').css('display', 'none');
		$('.SOMEselected').css('display', 'none');
		$('.IN_ONEselected').css('display', 'block');
		
	    } else if( selectedOption == "SOME" ) {
		$('.nbrAbsences').css('display', 'block');
		
		$('.ALLselected').css('display', 'none');
		$('.SOMEselected').css('display', 'block');
		$('.IN_ONEselected').css('display', 'none');
	    }
	    
	    $('.listeEtudiants').css('display', 'none');
	}
    })
    .change();
</script>